﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace ChinaDynastyTours.Controls
{
    class SysParameterCtrl
    {
        internal static string GetValueForKey(string key)
        {

            Database db = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand;

            string sql = string.Format(@"SELECT [value] FROM sys_Parameter WHERE [key]='{0}'", key);

            dbCommand = db.GetSqlStringCommand(sql);

            object obj = db.ExecuteScalar(dbCommand);
            if (obj != null)
                return obj.ToString();
            else
                return "";
            
        }

        internal static int UpdateValueForKey(string value,string key)
        {
            Database db = DatabaseFactory.CreateDatabase();
            string sql = string.Format(@"UPDATE sys_Parameter SET [Value]='{0}' WHERE [Key]='{1}'",value,key);

            return db.ExecuteNonQuery(CommandType.Text, sql);
        }
    }
}
